package com.chinasofti.thread02;

public class Demo03 {
    //TIMED_WAITING
    public static void main(String[] args) throws InterruptedException {

        Object obj = new Object();

        //定义一个内部线程
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("2.执行thread.start后，线程的状态" + Thread.currentThread().getState());
                synchronized (obj) {
                    try {
                        Thread.sleep(100);
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("2.执行thread.start后，线程的状态" + Thread.currentThread().getState());
                synchronized (obj) {
                    try {
                        Thread.sleep(100);
                        obj.notify();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("4.阻塞结束后，线程的状态"+ Thread.currentThread().getState());
            }
        });
        //获取start 之前的状态
        System.out.println("1.通过new初始化一个线程，但是没有调用start之前，线程的状态" + thread.getState());
        //启动线程
        thread.start();
        //休眠50
        Thread.sleep(50);
        //因为thread1需要休眠100毫秒
        System.out.println("3.等待阻塞时，线程状态" + thread.getState());
        Thread.sleep(300);
        System.out.println("5.等待阻塞时，线程状态" + thread.getState());
    }
}